<?php session_start();

if(isset($_SESSION['user_id'])) {
	//do nothing and stay on the current page..
} else {
	redirect("../../");
}

require_once("functions.php");
require_once("db.php");
//include("agency_calendar/agency_lib/wk_ns_json.php");

$q = $db->query("SELECT users.fname, users.lname, cal.model_name, cal.assignment, cal.date 
FROM users 
INNER JOIN cal 
ON cal.id_users = users.id
");



//$q = "SELECT users.fname, users.lname, cal.model_name, cal.date, cal.assignment FROM cal INNER JOIN users ON cal.id_users = users.id;";

//$result = mysql_fetch_object($sql);
//$result = mysql_query($q);
$q->setFetchMode(PDO::FETCH_ASSOC);

while($row = $q->fetch()) {
	
	/*print "<pre>";
		print_r($row);
	print "</pre>";
	*/

	if($row['fname'] == $_SESSION['fname'] && $row['lname'] == $_SESSION['lname']) {
		$items[] = $row;
	} 
}


/*
echo "<pre>";
	print_r($url_split);
echo "</pre>";
*/




/*echo "<pre>";
	print_r();
echo "</pre>";*/

confirm_logged_in();

$today = new DateTime(); //for today
			

?>

<!DOCTYPE html>
	
<html>
<head>
	<?php if($url_split[2] == "dashboard.php") : ?>
		<title>Persofolio Dashboard</title>
	<?php elseif(in_array("expense_report_add.php", $url_split)) : ?>
		<title>AC -> Job -> Invoice</title>
	<?php elseif(in_array("history.php", $url_split)) : ?>
		<title>AC -> Job -> History</title>
	<?php elseif(in_array("expense_report.php", $url_split)) : ?>
		<title>AC -> Job -> Invoice -> Expense Report</title>
	<?php elseif(in_array("expense_report_options.php", $url_split)) : ?>
		<title>AC -> Job -> Invoice -> Expense Report Options</title>
	<?php elseif(in_array("report_view_invoice.php", $url_split)) : ?>
		<title>AC -> Job -> Invoice -> Items</title>
	<?php elseif(in_array("wschedule2.php", $url_split)) : ?>
		<title>Agency Calendar -> Week View</title>
	<?php elseif(in_array("satb.php", $url_split)) : ?>
		<title>ATB -> Send A Talent Book</title>
	<?php endif; ?>
	
	<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>css/style.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>css/plain.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>js/jqueryui/css/ui-lightness/jquery-ui-1.8.17.custom.css" />
	<link rel="stylesheet" type="text/css" href="<?php echo $base_url; ?>js/tipsy/stylesheets/tipsy.css" />
	<link rel="stylesheet" href="<?php echo $base_url; ?>js/simplyscroll/jquery.simplyscroll-1.0.4.css" type="text/css" media="screen" />
	
	<!--<script type="text/javascript" src="<?php echo $base_url; ?>js/jquery.js"></script> -->
	<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script type="text/javascript" src="<?php echo $base_url; ?>js/jqueryui/js/jquery-ui-1.8.17.custom.min.js"></script>
	<script type="text/javascript" src="<?php echo $base_url; ?>js/tipsy/javascripts/jquery.tipsy.js"></script>
	<script src="<?php echo $base_url; ?>js/simplyscroll/jquery.simplyscroll-1.0.4.min.js" type="text/javascript"></script>
	<script type="text/javascript">
		$(document).ready(function() {
			
			$("#scroller").simplyScroll({
				className : 'simply-scroll_mini_pics',
				speed : 20,
				horizontal : true
			});
			
			$("#scroll_big").simplyScroll({
				className : 'simply-scroll_big_pics',
				speed : 20,
				horizontal : true
			});
			
			<?php foreach($items as $item) : ?>
			
				<?php if($item['assignment'] == FALSE) { 
					// do nothing
				} elseif($item['assignment'] == "Job") { ?>
				
					$('.job_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
					$(".job_mini").tipsy();
					
			<?php } elseif($item['assignment'] == "Option") { ?>
					
					$('.option_mini').attr("title", "<?php echo $item['model_name'] . " (" . $item['assignment'] . ") "; ?>");
					$(".option_mini").tipsy();
					
			<?php } elseif($item['assignment'] == "GoSee") { ?>
				
				$('.gosee_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
				$(".gosee_mini").tipsy();
				
			<?php } elseif($item['assignment'] == "Runway") { ?>
				
				$('.runway_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
				$(".runway_mini").tipsy();
				
			<?php } elseif($item['assignment'] == "Casting") { ?>
				
				$('.casting_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
				$(".casting_mini").tipsy();
				
			<?php } elseif($item['assignment'] == "Fitting") { ?>
				
				$('.fitting_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
				$(".fitting_mini").tipsy();
				
			<?php } elseif($item['assignment'] == "Appointment") { ?>
				
				$('.appointment_mini').attr("title", "<?php echo $item['assignment'] . " - " . $item['model_name']; ?>");
				$(".appointment_mini").tipsy();
				
			<?php } ?>
			
			<?php endforeach; ?>
			
			var acPlus = $("#ac_plus");
				miniMonth = $(".month");
				
			acPlus.click(function() {
				miniMonth.fadeToggle();
				return false;
			});
			
			if(window.location.search == "") {
				miniMonth.css({"display" : "none"});
			} else if(window.location.search == "?yearID="){
				miniMonth.show();
			}

			
			//for satb step 4
			$(".contact_name_options").hide();
			$(".contact_name_container").hide();
			
			/*$(".satb_contacts li").click(function() {
				var cName = $(".contact_name_container");
					cNameV = $(".contact_name_container:visible"); 
				
				cName.toggle('slow');
				
				//$(".contact_name_container").show();
			});*/
				
			$(".<?php echo strtolower($today->format('l-d')); ?>_wk").addClass("today_date");
			$(".<?php echo strtolower($today->format('l-d')); ?>_head").addClass("today_head");

			var editing = false;

			/*$('.events_for b').on('click', function(e) {

			   if(!editing) e.stopPropagation();
			    
			    //var this = $(this);
			    //var text = this.text();
			    this.replaceWith('<input type="text" value="' + text + '" class="editbox"/>');
			    editing = true;
			
			});*/

			//var this = $(this);
			/*$(".editable").keypress(function (e) {

				if (e.keyCode==13) $(this).blur();
				if (e.keyCode==8) e.preventDefault();
    			if (e.keyCode==15) $(this).blur();

    			//return false;

			});*/

			
			$.getJSON('<?php echo $base_url; ?>agency_calendar/agency_lib/wk_ns_json.php', function(data) {

					var mn = $('.editable');
					var names = data.model_name;

					mn.autocomplete({
						source : names
					});
					
			});

			var evnt_e = {

				init : function() {

					var type = $('.wrkwk p').data('type');
			        var edit_event = $('.edit_evnt_container');
			        $('.edit_evnt_container').hide();

					//$('.assignmt_img').attr('title', 'Edit ' + type).tipsy({gravity : 'e'});
					$('.assignment_type').hover(function() {

						//$('.edit_evnt_container').fadeToggle(400);
						$(this).find('.edit_evnt_container').fadeToggle(400);
						$('.edit_evnt').attr('title', 'Edit Event').tipsy();
						$('.delete_evnt').attr('title', 'Delete Event').tipsy();

					});
			  		
			 		$('#qk_add_container').hide();

			 		$('#add_event').click(function() {
			 			$('#qk_add_container').dialog({
			 				resizable : false,
			 				width : 375,
			 				minHeight : 200,
			 				modal : true,
			 				draggable : false,
			 				dialogClass : 'cr_evnt_modal',
			 				create : function(event, ui) {
			 					$(this).parents('.ui-dialog').css({
			 						'margin' : '0 auto'
			 					})
			 				}
			 			});
			 		});

				} //end init method
			};

			evnt_e.init(); 

			/*mn.autocomplete({
				source : names.model_name
			});*/

			(function() {
				var date = $('#datepicker');
				date.datepicker({
					dateFormat : 'yy-mm-dd',
					showOn: "both",
					buttonImage: "<?php echo $base_url;?>images/calendar.gif",
					buttonImageOnly: true
				});

				var qa = $('#qa_dp');
				qa.datepicker({
					dateFormat : 'yy-mm-dd',
					showOn: "both",
					buttonImage: "<?php echo $base_url;?>images/calendar.gif",
					buttonImageOnly: true
				});
			})();

		
		//$.getJSON('/agency_calendar/agency_lib/wk_ns_json.php', );	

		//fix this when i get the chance - basically it
		//uses a method to obtain the yearID if appended to the URL
		//its supposed to hide the mini cal with + when clicked.. make it work
/*		var miniCal = {

			//get method for the mini cal
			get : function () {
				var miniCalGET = <?php echo json_encode($_GET['yearID']); ?>;
				var $this = $(this);

				console.log(miniCalGET);
			}	
		};

		miniCal.get();
*/	
			var cal_tabs = {
				init : function() {
					console.log(location.pathname.split("/"));
					var path = location.pathname.split("/");
					
					for (var i = path.length - 1; i >= 0; i--) {
						
					    switch(path[i]) {
					    
					        case "job" :
					           $('.job_bg').addClass('job-selected');
					           $('#option_color').addClass('job_gradient');
					        break;
					        
					        case "option" :
					            $('.option_bg').addClass('option-selected');
					            $('#option_color').addClass('option_gradient');
					        break;
					        
					    }
					}
					/*var tevnt;
					var assign = $.inArray(tevnt, path);
					
					switch(tevnt) {
						case "job" :
							console.log(tevnt);
							$('.job_bg').addClass('job-selected');
							$('#option_color').addClass('job_gradient');
						break;
						
						case "option" :
							console.log(tevnt);
							$('.option_bg').addClass('option-selected');
						break;
						
					}*/
					
					
					/*if($.inArray("job", path)) {
					
						$('.job_bg').addClass('job-selected');
						$('#option_color').addClass('job_gradient');
						
					} else if($.inArray("option", path)) { 
					
						$('.option_bg').addClass('option-selected');
					}*/
				}
			};
			
			cal_tabs.init();

		}); //end document.ready

	</script>
</head>

<body>
	<!--<h1>TEST PERSOFOLIO HOMEPAGE</h1> -->
	
	<div id="head_wrap">
		<div id="head">
			<ul id="head_text">
				<li><a href="<?php echo $base_url; ?>dashboard.php">dashboard</a></li>
				<li>|</li>
				<li>polls</li>
				<li>|</li>
				<li>forums</li>
				<li>|</li>
				<li>search</li>
				<li>|</li>
				<li>helpdesk 24/7</li>
			</ul>
			
			<div id="icon">
				<a href="<?php echo $base_url; ?>dashboard.php"><img src="<?php echo $base_url; ?>images/persofolio3.png" width="105" height="20" alt="logo" /></a>
			</div>
		</div>
		<div id="under_head"></div>
	</div>
	
	<div id="tab_wrap">
		<div id="tab">
			<?php if($url_split[2] == "dashboard.php") : ?>
				<span>Dashboard</span>
			<?php elseif(in_array("atb", $url_split)) :?>
				<span>Agency Talent Book Center</span>
			<?php elseif(in_array("agency_calendar", $url_split)) : ?>
				<span>Agency Calendar</span>
			<?php endif; ?>
			
		</div>
	</div>
	
	<div id="wrapper_content">
		
	<?php include('sidebar.php'); ?>
	
	<div id="wrapper">
		<div id="main_content">
			<div id="time_bar">
				<?php echo 'Today is ' . date('l - F d, Y'); ?>
			</div>
			<div id="tab_under"></div>